package com.seu.project.seuquiz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seu.project.seuquiz.common.BaseResponse;
import com.seu.project.seuquiz.common.ResultUtils;
import com.seu.project.seuquiz.model.req.CollegeContestReq;
import com.seu.project.seuquiz.model.req.CollegeUsersContestParamReq;
import com.seu.project.seuquiz.model.res.CollegeContestRes;
import com.seu.project.seuquiz.model.res.CollegeUsersContestParamRes;
import com.seu.project.seuquiz.service.CollegeBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author SoftPro
 * @createDate: 2023-07-16 17:28
 */
@RestController
@RequestMapping("/college/biz")
@Slf4j
@Api(tags = "学院竞赛查询接口 -- 查询学院、学生竞速信息")
public class CollegeBizController {

    @Resource
    private CollegeBizService collegeBizService;

    /**
     * 根据学院、专业、一卡通账号等查询学院整体参与竞赛数据   todo: 待测试
     * @param request
     * @return
     */
    @GetMapping("/list/users/contest")
    @ApiOperation("listCollegeUsersContestByParam：列出学院每个学生参与竞赛情况")
    public BaseResponse<List<CollegeUsersContestParamRes>> listCollegeUsersContestByParam(CollegeUsersContestParamReq request) {
        if (request == null) {
            return null;
        }

        List<CollegeUsersContestParamRes> queryContestParamReqs = collegeBizService.listCollegeUsersContestByParam(request);
        if (request.getScore() != null && request.getScore() >= 0) {
            queryContestParamReqs = queryContestParamReqs.stream().filter(it -> it.getScore() == request.getScore() ).collect(Collectors.toList());
        }
        return ResultUtils.success(queryContestParamReqs);
    }

    /**
     * 分页根据学院、专业、一卡通账号等查询学院整体参与竞赛数据   todo: 待测试
     * @param request
     * @return
     */
    @GetMapping("/list/users/contest/page")
    @ApiOperation("listCollegeUsersContestByParamAndPage：分页列出学院每个学生参与竞赛情况")
    public BaseResponse<Page<CollegeUsersContestParamRes>> listCollegeUsersContestByParamAndPage(CollegeUsersContestParamReq request) {
        if (request == null) {
            return null;
        }

        long current = request.getCurrent();
        long size = request.getPageSize();

        Page<CollegeUsersContestParamRes> queryContestParamReqs = collegeBizService.listCollegeUsersContestByParamAndPage(request, new Page(current, size));
        return ResultUtils.success(queryContestParamReqs);
    }

    /**
     * 列出学院整体参与竞赛情况             todo: 待测试
     * @param request
     * @return
     */
    @GetMapping("/list/college/contest")
    @ApiOperation("listCollegeUsersContestByParam：列出学院整体参与竞赛情况")
    public BaseResponse<List<CollegeContestRes>> listCollegeUsersContestByParam(CollegeContestReq request) {
        if (request == null) {
            return null;
        }

        List<CollegeContestRes> collegeContestResList = collegeBizService.listCollegeContestRes(request);
        return ResultUtils.success(collegeContestResList);
    }

    /**
     * 分页列出学院整体参与竞赛情况       todo: 待测试
     * @param request
     * @return
     */
    @GetMapping("/list/college/contest/page")
    @ApiOperation("listCollegeUsersContestByParam：分页列出学院整体参与竞赛情况")
    public BaseResponse<Page<CollegeContestRes>> listCollegeUsersContestByParamByPage(CollegeContestReq request) {
        if (request == null) {
            return null;
        }
        long current = request.getCurrent();
        long size = request.getPageSize();

        Page<CollegeContestRes> collegeContestResList = collegeBizService.listCollegeContestResByPage(request, new Page(current, size));
        return ResultUtils.success(collegeContestResList);
    }

}
